﻿using DDD.Application.Services;
using DDD.Domain.IRepository;
using DDD.Infrastructure.IoC;
using DDD.Infrastructure.Repository;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;

namespace WebApp
{
    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            // IIoCContainer container = new StructureMapContainer();
            IIoCContainer container = new AutofacContainer();
            //IIoCContainer container = Activator.CreateInstance(
            //    Type.GetType("DDD.Infrastructure.IoC.StructureMapContainer,DDD.Infrastructure")
            //    ) as IIoCContainer;

            container.Add<IStudentRepository, StudentRepository>();
            container.Add<IStudentService, StudentService>();
            IoCEngine.Init(container);
            ControllerBuilder.Current.SetControllerFactory(new IoCControllerFactory());

            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
    }
}
